package com.scaffold.authority.dao;

import java.util.List;

import org.hibernate.criterion.DetachedCriteria;
import org.hibernate.criterion.Restrictions;
import org.springframework.stereotype.Repository;

import com.scaffold.authority.entity.UserAuthorityRelation;

@Repository
public class UserAuthorityRelationDAO extends BasicBizDAO<UserAuthorityRelation,Long>{

	public List<UserAuthorityRelation> findByUserId(Long userId) {
		return this.findListByProperty("userId", userId);
	}
	public List<UserAuthorityRelation> findByAuthorityId(Long authorityId) {
		return this.findListByProperty("authorityId", authorityId);
	}

	public UserAuthorityRelation findItem(Long userId, Long authorityId) {
		DetachedCriteria criteria = DetachedCriteria.forClass(this.persistentClass);
		criteria.add(Restrictions.eq("userId", userId));
		criteria.add(Restrictions.eq("authorityId", authorityId));		return this.findUniqueByCriteria(criteria);
	}
}
